<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns:yui="http://yuilibrary.com/rdf/1.0/yui.rdf#">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	<title>API: CWN2   Map.js  (YUI Library)</title>

	<link rel="stylesheet" type="text/css" href="assets/reset-fonts-grids-min.css?stamp=1308058435.87" />
	<link rel="stylesheet" type="text/css" href="assets/api.css?stamp=1308058435.87" />

    <script type="text/javascript" src="assets/api-js?stamp=1308058435.87"></script>
    <script type="text/javascript" src="assets/ac-js?stamp=1308058435.87"></script>
</head>

<body id="yahoo-com">

<div id="doc3" class="yui-t2">
	<div id="hd">
        <h1><a href="/CartoWebNet2/lib/Cwn2/" title="CartoWebNet2 Javascript Library">CartoWebNet2 Javascript Library</a></h1>
        <h3>CWN2&nbsp; <span class="subtitle">1.0.0</span></h3>
        <a href="./index.html" title="CartoWebNet2 Javascript Library">CartoWebNet2 Javascript Library</a> 
            &gt; <a href="./module_cwn2.html" title="CWN2">CWN2</a>
                
                 &gt; Map.js (source view) 
        <form onsubmit="return false">
            <div id="propertysearch">
                Search: <input autocomplete="off" id="searchinput" />
                <div id="searchresults">
                    &nbsp;
                </div>
            </div>
        </form>
	</div>

	<div id="bd">
		<div id="yui-main">
			<div class="yui-b">
            <form action="#" name="yui-classopts-form" method="get" id="yui-classopts-form">
                <fieldset>
                    <legend>Filters</legend>
                <span class="classopts"><input type="checkbox" name="show_private" id="show_private" /> <label for="show_private">Show Private</label></span>
                <span class="classopts"><input type="checkbox" name="show_protected" id="show_protected" /> <label for="show_protected">Show Protected</label></span>
                <span class="classopts"><input type="checkbox" name="show_deprecated" id="show_deprecated" /> <label for="show_deprecated">Show Deprecated</label></span>
                </fieldset>
            </form>

                    <div id="srcout">
                        <style>
                            #doc3 .classopts { display:none; }
                        </style>
<div class="highlight"><pre><span class="c1">//#include &lt;base.js&gt;</span>
<span class="c1">//#include &lt;openlayersExt.js&gt;</span>
<span class="c1">//#include &lt;event.js&gt;</span>


<span class="cm">/**</span>
<span class="cm">* </span>
<span class="cm">* Classe CWN2.Map - Inherited from Openlayers.Map</span>
<span class="cm">* </span>
<span class="cm">* @namespace CWN2</span>
<span class="cm">* @class Map</span>
<span class="cm">* @constructor</span>
<span class="cm">* @param {String} div Div id</span>
<span class="cm">* @param {Object} options Hashtable of extra options to tag onto the layer</span>
<span class="cm">* </span>
<span class="cm">*/</span>

<span class="nx">CWN2</span><span class="p">.</span><span class="nx">Map</span> <span class="o">=</span> <span class="nx">OpenLayers</span><span class="p">.</span><span class="nx">Class</span><span class="p">(</span><span class="nx">OpenLayers</span><span class="p">.</span><span class="nx">Map</span><span class="p">,</span> <span class="p">{</span>
	
    <span class="cm">/*</span>
<span class="cm">     * Constant: DEFAULT_PARAMS</span>
<span class="cm">     * {Object} Hashtable of default parameter key/value pairs </span>
<span class="cm">     */</span>
    <span class="nx">DEFAULT_PARAMS</span><span class="o">:</span> <span class="p">{},</span>
    
    <span class="cm">/*</span>
<span class="cm">     * Constructor: CWN2.Map</span>
<span class="cm">     *</span>
<span class="cm">     * Parameters:</span>
<span class="cm">     * div - {String} </span>
<span class="cm">     * options - {Object} Hashtable of extra options to tag onto the layer</span>
<span class="cm">     */</span>
	
    <span class="nx">initialize</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">div</span><span class="p">,</span> <span class="nx">options</span><span class="p">)</span> <span class="p">{</span>
    	<span class="nx">OpenLayers</span><span class="p">.</span><span class="nx">Map</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">initialize</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="nx">arguments</span><span class="p">);</span>
    <span class="p">},</span>
	
	<span class="cm">/**</span>
<span class="cm">	* </span>
<span class="cm">	* Load the configuration. </span>
<span class="cm">	* Require that a CWN2.configuration object has been created  </span>
<span class="cm">	* </span>
<span class="cm">	* @method loadConfig</span>
<span class="cm">	* </span>
<span class="cm">	*/</span>    
    <span class="nx">loadConfig</span><span class="o">:</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
		
		<span class="k">if</span> <span class="p">(</span><span class="nx">CWN2</span><span class="p">.</span><span class="nx">base</span><span class="p">.</span><span class="nx">DEBUG</span><span class="p">)</span> <span class="p">{</span>
			<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;CWN2.Map.load&#39;</span><span class="p">);</span>
		<span class="p">}</span>
		
		<span class="kd">var</span> <span class="nx">config</span> <span class="o">=</span> <span class="nx">CWN2</span><span class="p">.</span><span class="nx">configuration</span><span class="p">;</span>
		
		<span class="c1">// carico le mapOptions</span>
		<span class="kd">var</span> <span class="nx">mapOptions</span> <span class="o">=</span> <span class="nx">config</span><span class="p">.</span><span class="nx">mapOptions</span><span class="p">;</span>
		<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">key</span> <span class="k">in</span> <span class="nx">mapOptions</span><span class="p">)</span> <span class="p">{</span>
			<span class="k">this</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">=</span> <span class="nx">mapOptions</span><span class="p">[</span><span class="nx">key</span><span class="p">];</span>
		<span class="p">}</span>
		
		<span class="c1">// aggiungo i layers alla mappa OL</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">loadLayers</span><span class="p">(</span><span class="nx">config</span><span class="p">.</span><span class="nx">layers</span><span class="p">);</span>

		<span class="c1">// registro il controllo per la selezione delle feature dei livelli vettoriali</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">activateSelectFeatureControl</span><span class="p">();</span>
    	
		<span class="c1">// aggiungo i controlli per la mappa OL</span>
		<span class="c1">// TODO</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">addControl</span><span class="p">(</span><span class="k">new</span> <span class="nx">OpenLayers</span><span class="p">.</span><span class="nx">Control</span><span class="p">.</span><span class="nx">LayerSwitcher</span><span class="p">({}));</span>


		<span class="c1">// vado allo zoom iniziale</span>
		<span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="k">this</span><span class="p">.</span><span class="nx">getCenter</span><span class="p">()){</span>
			<span class="k">this</span><span class="p">.</span><span class="nx">zoomToMaxExtent</span><span class="p">();</span>
		<span class="p">}</span>

	<span class="p">},</span>

	<span class="cm">/**</span>
<span class="cm">	* </span>
<span class="cm">	* Add an array of layers to the map. </span>
<span class="cm">	* </span>
<span class="cm">	* @method loadLayers</span>
<span class="cm">	* @param [{layerConfig}] layers Array of layerConfig objects </span>
<span class="cm">	* </span>
<span class="cm">	*/</span>    
	
    <span class="nx">loadLayers</span><span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">layers</span><span class="p">)</span> <span class="p">{</span>
		
		<span class="k">if</span> <span class="p">(</span><span class="nx">CWN2</span><span class="p">.</span><span class="nx">base</span><span class="p">.</span><span class="nx">DEBUG</span><span class="p">)</span> <span class="p">{</span>
			<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;CWN2.Map.loadLayers&#39;</span><span class="p">);</span>
		<span class="p">}</span>

		<span class="c1">// aggiungo i layers alla mappa OL</span>
		<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="nx">layers</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
			<span class="k">this</span><span class="p">.</span><span class="nx">loadLayer</span><span class="p">(</span><span class="nx">layers</span><span class="p">[</span><span class="nx">i</span><span class="p">]);</span>
		<span class="p">}</span>

	<span class="p">},</span>	

	<span class="cm">/**</span>
<span class="cm">	* </span>
<span class="cm">	* Add a layer to the map. </span>
<span class="cm">	* </span>
<span class="cm">	* @method loadLayer</span>
<span class="cm">	* @param {layerConfig} layerConfig A layerConfig object </span>
<span class="cm">	* </span>
<span class="cm">	*/</span>    

    <span class="nx">loadLayer</span><span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">layerConfig</span><span class="p">)</span> <span class="p">{</span>
	
    	<span class="k">if</span> <span class="p">(</span><span class="nx">CWN2</span><span class="p">.</span><span class="nx">base</span><span class="p">.</span><span class="nx">DEBUG</span><span class="p">)</span> <span class="p">{</span>
			<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;CWN2.Map.loadLayer&#39;</span><span class="p">);</span>
		<span class="p">}</span>

    	<span class="c1">// creo il layer OL e lo aggiungo alla mappa</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">addLayer</span><span class="p">(</span><span class="nx">CWN2</span><span class="p">.</span><span class="nx">layerFactory</span><span class="p">.</span><span class="nx">createLayer</span><span class="p">(</span><span class="nx">layerConfig</span><span class="p">));</span>
	<span class="p">},</span>	
	

	<span class="cm">/**</span>
<span class="cm">	* </span>
<span class="cm">	* Activate the select feature control for all the vector layers of the map. </span>
<span class="cm">	* </span>
<span class="cm">	* @method activateSelectFeatureControl</span>
<span class="cm">	* </span>
<span class="cm">	*/</span> 
	
    <span class="nx">activateSelectFeatureControl</span><span class="o">:</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
		
		<span class="k">if</span> <span class="p">(</span><span class="nx">CWN2</span><span class="p">.</span><span class="nx">base</span><span class="p">.</span><span class="nx">DEBUG</span><span class="p">)</span> <span class="p">{</span>
			<span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;CWN2.Map.activateSelectFeatureControl&#39;</span><span class="p">);</span>
		<span class="p">}</span>

		<span class="c1">// carico l&#39;array con i layer vettoriali</span>
		<span class="kd">var</span> <span class="nx">vectLayerArray</span> <span class="o">=</span> <span class="p">[];</span>
		<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="k">this</span><span class="p">.</span><span class="nx">layers</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
			<span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">layers</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">CLASS_NAME</span><span class="o">===</span><span class="s1">&#39;OpenLayers.Layer.Vector&#39;</span><span class="p">)</span> <span class="p">{</span>
				<span class="k">this</span><span class="p">.</span><span class="nx">layers</span><span class="p">[</span><span class="nx">i</span><span class="p">].</span><span class="nx">events</span><span class="p">.</span><span class="nx">on</span><span class="p">({</span>
				    <span class="s1">&#39;featureselected&#39;</span><span class="o">:</span> <span class="nx">CWN2</span><span class="p">.</span><span class="nx">event</span><span class="p">.</span><span class="nx">onFeatureSelect</span><span class="p">,</span>
				    <span class="s1">&#39;featureunselected&#39;</span><span class="o">:</span> <span class="nx">CWN2</span><span class="p">.</span><span class="nx">event</span><span class="p">.</span><span class="nx">onFeatureUnselect</span>
				<span class="p">});</span>
				<span class="nx">vectLayerArray</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">layers</span><span class="p">[</span><span class="nx">i</span><span class="p">]);</span>
			<span class="p">}</span>
		<span class="p">}</span>
		<span class="c1">// attivo il controllo</span>
		<span class="kd">var</span> <span class="nx">select_feature_control</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">OpenLayers</span><span class="p">.</span><span class="nx">Control</span><span class="p">.</span><span class="nx">SelectFeature</span><span class="p">(</span><span class="nx">vectLayerArray</span><span class="p">);</span>
		<span class="k">this</span><span class="p">.</span><span class="nx">addControl</span><span class="p">(</span><span class="nx">select_feature_control</span><span class="p">);</span>
		<span class="nx">select_feature_control</span><span class="p">.</span><span class="nx">activate</span><span class="p">();</span>
		
	<span class="p">},</span>		

	<span class="nx">CLASS_NAME</span><span class="o">:</span> <span class="s2">&quot;CWN2.Map&quot;</span>
<span class="p">});</span>
</pre></div>
                    </div>
			</div>
		</div>
		<div class="yui-b">
            <div class="nav">

                    <div id="moduleList" class="module">
                        <h4>Modules</h4>
                        <ul class="content">
                                <li class="selected"><a href="module_CWN2.html" title="CWN2">CWN2</a></li>
                        </ul>
                    </div>

                    <div id="classList" class="module">
                        <h4>Classes</h4>
                        <ul class="content">
                                <li class=""><a href="CWN2.configuration.html" title="CWN2.configuration">CWN2.configuration</a></li>
                                <li class=""><a href="CWN2.event.html" title="CWN2.event">CWN2.event</a></li>
                                <li class=""><a href="CWN2.json.html" title="CWN2.json">CWN2.json</a></li>
                                <li class=""><a href="CWN2.layerFactory.html" title="CWN2.layerFactory">CWN2.layerFactory</a></li>
                                <li class=""><a href="CWN2.Map.html" title="CWN2.Map">CWN2.Map</a></li>
                        </ul>
                    </div>

                    <div id="fileList" class="module">
                        <h4>Files</h4>
                        <ul class="content">        
                                <li class=""><a href="base.js.html" title="base.js">base.js</a></li>
                                <li class=""><a href="configuration.js.html" title="configuration.js">configuration.js</a></li>
                                <li class=""><a href="event.js.html" title="event.js">event.js</a></li>
                                <li class=""><a href="json.js.html" title="json.js">json.js</a></li>
                                <li class=""><a href="layerFactory.js.html" title="layerFactory.js">layerFactory.js</a></li>
                                <li class="selected"><a href="Map.js.html" title="Map.js">Map.js</a></li>
                                <li class=""><a href="openlayersExt.js.html" title="openlayersExt.js">openlayersExt.js</a></li>
                        </ul>
                    </div>





            </div>
		</div>
	</div>
	<div id="ft">
        <hr />
        Copyright &copy; 2011 Yahoo! Inc. All rights reserved.
	</div>
</div>
<script type="text/javascript">
    ALL_YUI_PROPS = [{"url": "CWN2.Map.html#method_activateSelectFeatureControl", "access": "", "host": "CWN2.Map", "type": "method", "name": "activateSelectFeatureControl"}, {"url": "CWN2.configuration.html#property_buttons", "access": "", "host": "CWN2.configuration", "type": "property", "name": "buttons"}, {"url": "CWN2.configuration.html#property_controls", "access": "", "host": "CWN2.configuration", "type": "property", "name": "controls"}, {"url": "CWN2.layerFactory.html#method_createLayer", "access": "", "host": "CWN2.layerFactory", "type": "method", "name": "createLayer"}, {"url": "CWN2.configuration.html#method_getLayerConfigByName", "access": "", "host": "CWN2.configuration", "type": "method", "name": "getLayerConfigByName"}, {"url": "CWN2.configuration.html#property_layers", "access": "", "host": "CWN2.configuration", "type": "property", "name": "layers"}, {"url": "CWN2.configuration.html#property_layout", "access": "", "host": "CWN2.configuration", "type": "property", "name": "layout"}, {"url": "CWN2.configuration.html#method_load", "access": "", "host": "CWN2.configuration", "type": "method", "name": "load"}, {"url": "CWN2.json.html#method_load", "access": "", "host": "CWN2.json", "type": "method", "name": "load"}, {"url": "CWN2.json.html#method_loadAsync", "access": "", "host": "CWN2.json", "type": "method", "name": "loadAsync"}, {"url": "CWN2.Map.html#method_loadConfig", "access": "", "host": "CWN2.Map", "type": "method", "name": "loadConfig"}, {"url": "CWN2.Map.html#method_loadLayer", "access": "", "host": "CWN2.Map", "type": "method", "name": "loadLayer"}, {"url": "CWN2.Map.html#method_loadLayers", "access": "", "host": "CWN2.Map", "type": "method", "name": "loadLayers"}, {"url": "CWN2.configuration.html#property_mapOptions", "access": "", "host": "CWN2.configuration", "type": "property", "name": "mapOptions"}, {"url": "CWN2.configuration.html#property_name", "access": "", "host": "CWN2.configuration", "type": "property", "name": "name"}, {"url": "CWN2.event.html#method_onFeatureSelect", "access": "", "host": "CWN2.event", "type": "method", "name": "onFeatureSelect"}, {"url": "CWN2.event.html#method_onFeatureUnselect", "access": "", "host": "CWN2.event", "type": "method", "name": "onFeatureUnselect"}];
</script>
</body>
</html>
